<?php
/*
# $Id$
#
# Dump the database.
*/

use Buan\Database;
use Buan\Config;

// Init
if(!defined('CRON')) {
	die("Cannot execute this script directly.");
}

// Only run every 24 hours
if(time()-$__lastRunTime<(24*60*60)) {
	return 0;
}

// Dump
$dbInfo = Database::getConnectionInfo('default');
$dbName = preg_replace("/^.*?dbname=(.*?)$/i", "$1", $dbInfo['dsn']);
$dbUser = $dbInfo['username'];
$dbPass = $dbInfo['password'];
$tgtFile = Config::get('app.dir.backups').'/db-'.date("dmY", time()).'.sql';
$cmd = "/usr/local/bin/mysqldump -u{$dbUser} ".($dbPass=='' ? '' : "-p{$dbPass}")." {$dbName} > {$tgtFile}";
exec($cmd);
?>